#region File Description
//-----------------------------------------------------------------------------
// PauseMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
#endregion

namespace Magnet
{
    /// <summary>
    /// The credits screen comes up when the player exits the game.
    /// </summary>
    class CreditsScreen : GameScreen
    {
        #region Fields

        bool otherScreensAreGone;

        Texture2D creditsScreen;

        #endregion

        #region Initialization


        /// <summary>
        /// The constructor is private: loading screens should
        /// be activated via the static Load method instead.
        /// </summary>
        private CreditsScreen()
        {
            TransitionOnTime = TimeSpan.FromSeconds(5);

            ContentManager content = ScreenManager.Content;

            creditsScreen = content.Load<Texture2D>("Menu\\credits");
        }


        /// <summary>
        /// Activates the loading screen.
        /// </summary>
        public static void ExitGame(ScreenManager screenManager)
        {
            // Tell all the current screens to transition off.
            foreach (GameScreen screen in screenManager.GetScreens())
                screen.ExitScreen();

            // Create and activate the loading screen.
            CreditsScreen creditsScreen = new CreditsScreen();

            screenManager.AddScreen(creditsScreen);
        }


        #endregion

        #region Update and Draw


        /// <summary>
        /// Updates the credits screen.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            if (InputManager.IsKeyTriggered(InputManager.OK)
                || InputManager.IsKeyTriggered(InputManager.BACK)
                || otherScreensAreGone)
                ScreenManager.Game.Exit();
        }


        /// <summary>
        /// Draws the loading screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            // If we are the only active screen, that means all the previous screens
            // must have finished transitioning off. We check for this in the Draw
            // method, rather than in Update, because it isn't enough just for the
            // screens to be gone: in order for the transition to look good we must
            // have actually drawn a frame without them before we perform the load.
            if ((ScreenState == ScreenState.Active) &&
                (ScreenManager.GetScreens().Length == 1))
            {
                otherScreensAreGone = true;
            }

            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            spriteBatch.Begin();

            spriteBatch.Draw(creditsScreen, new Vector2(0, 0), Color.White);

            spriteBatch.End();
        }


        #endregion
    }
}
